﻿import com.gamemeal.mvc.IModelField;
import com.gamemeal.mx.Event;
import com.gamemeal.mx.IEventDispatcher;
import mx.events.EventDispatcher;
/**
 * @author Colin
 */
class com.gamemeal.mvc.datatype.MFObject implements IModelField,IEventDispatcher{
	public var value:Object;
	private var storeProcedure : Function;
	public function MFObject(value:Object,storeProcedure:Function){
		EventDispatcher.initialize(this);
		this.value = value;
		this.storeProcedure = storeProcedure;
		this.watch('value',watchHandler);
	};
	
	private function watchHandler(prop:Object, oldVal:Object, newVal:Object):Object{
		if(storeProcedure!=undefined)newVal = storeProcedure(prop, oldVal, newVal);
		dispatchEvent(new Event(this,Event.CHANGE,newVal));
		return newVal;
	}
	
	public function dispatchEvent(event : Event) : Void {
	}

	public function addEventListener(eventType : String, handler : Function) : Void {
	}

	public function removeEventListener(eventType : String, handler : Function) : Void {
	}
}